package drds.configuration.db.xml_mapping.dynamic_tag.sql_template;

import drds.configuration.db.xml_mapping.configuration.Configuration;
import drds.configuration.db.xml_mapping.dynamic_tag.token_handler.PreparedParameterMapping;
import drds.configuration.db.xml_mapping.dynamic_tag.token_handler.PreparedParameterMappingTokenHandler;
import drds.configuration.db.xml_mapping.dynamic_tag.token_handler.TokenParser;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;


abstract class AbstractSqlTemplate implements SqlTemplate {
    public Configuration configuration;

    public AbstractSqlTemplate(Configuration configuration) {
        this.configuration = configuration;
    }

    public SqlTemplate parse(String originalSql) {
        List<PreparedParameterMapping> preparedParameterMappingList = new ArrayList<PreparedParameterMapping>();
        PreparedParameterMappingTokenHandler preparedParameterMappingTokenHandler = new PreparedParameterMappingTokenHandler(configuration, preparedParameterMappingList);
        TokenParser tokenParser = new TokenParser("#{", "}", preparedParameterMappingTokenHandler);
        String sql = tokenParser.parse(originalSql);
        return new StaticSqlTemplate(configuration, sql, preparedParameterMappingList);
    }

    @Override
    public abstract Bind bindWith(Map<String, Object> parameterObject);
}
